<script setup>
import { inject, computed } from 'vue'


// 注入数据
const infoData = inject('infoData', [])
const loading = inject('loading', true)

// 过滤出教学相关的信息并按title分组
const teachingInfos = computed(() => {
  const teachingTitles = [
    '主讲课程',
    '主持的教研项目', 
    '获得的教学奖',
    '指导学生创新创业情况',
    '指导学生获奖',
    '指导学生论文情况'
  ]
  const grouped = {}
  
  teachingTitles.forEach(title => {
    const items = infoData.value.filter(info => info.title === title)
      .sort((a, b) => a.displayOrder - b.displayOrder)
    if (items.length > 0) {
      grouped[title] = items
    }
  })
  
  return grouped
})
</script>

<template>
  <div class="teaching-container">
    <h1 class="section-title">主要教学成果</h1>
    
    <div v-if="loading" class="loading-container">
      <el-skeleton :rows="5" animated />
    </div>
    
    <div v-else-if="Object.keys(teachingInfos).length === 0" class="empty-state">
      <p>暂无教学成果数据</p>
    </div>
    
    <div v-else class="info-content">
      <div v-for="(items, category) in teachingInfos" :key="category" class="category-section">
        <h2 class="category-title">{{ category }}</h2>
        <div v-for="(info, index) in items" :key="info.id" class="info-item">
          <div class="info-number">[{{ index + 1 }}]</div>
          <div class="info-description" v-html="formatDescription(info.description)"></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// 格式化描述文本，将换行符转换为 <br> 标签
function formatDescription(text) {
  if (!text) return ''
  return text.replace(/\n/g, '<br>')
}
</script>

<style scoped>
.teaching-container {
  padding: 2rem;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.section-title {
  font-size: 1.8rem;
  color: #333;
  margin-bottom: 1.5rem;
  padding-bottom: 0.8rem;
  border-bottom: 2px solid #eaeaea;
  position: relative;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 80px;
  height: 2px;
  background-color: #409EFF;
}

.loading-container {
  padding: 1rem 0;
}

.empty-state {
  text-align: center;
  padding: 3rem;
  color: #909399;
  font-size: 1.2rem;
}

.info-content {
  margin-top: 1.5rem;
}

.category-section {
  margin-bottom: 2.5rem;
}

.category-section:last-child {
  margin-bottom: 0;
}

.category-title {
  font-size: 1.3rem;
  color: #409EFF;
  margin-bottom: 1rem;
  padding-left: 0.5rem;
  border-left: 4px solid #409EFF;
  font-weight: 600;
}

.info-item {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px dashed #eaeaea;
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
}

.info-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.info-number {
  font-size: 1rem;
  font-weight: 600;
  color: #409EFF;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.info-description {
  font-size: 1rem;
  line-height: 1.8;
  color: #333;
  text-align: justify;
  flex: 1;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .teaching-container {
    padding: 1.5rem;
  }
  
  .section-title {
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  .teaching-container {
    padding: 1rem;
  }
  
  .section-title {
    font-size: 1.3rem;
  }
  
  .info-description {
    font-size: 0.9rem;
  }
}
</style>